Main Page | Projects IndexGallery Index | Data & Infomation

 

MODBUS RTU SLAVE

Overview

 

The following program uses the CRC16 routine previously described in order to respond to MODBUS RTU function 3 multi-holding register reads and function 6 single holding register writes.

 

Windows

 

The project consists of the three windows as shown here:

The demo program can support up to 100 holding registers as defined by the 'Header Address' and 'Number' elements on the left-hand window. The pull-down menu of this window enables the buffer view and comms settings windows shown in the middle and right of the above image.

Once the comms settings are correctly entered, the 'Open Port' on the main window will setup the comms port in order to receive incoming messages.

As these arrive, they are placed in in the rx buffer shown in the top pain of the middle window. These messages may arrive in one, two or even three chunks into the rx buffer. Every time the receive buffer is written to the program checks to see if it contains a message that includes the correct slave address and function code, if this is the case the message is written into the decoding buffer and a CRC check is performed on the message of the decoding buffer. If the message passes the CRC then the original message from the rx_buffer is deleted and the message within the decoding buffer is disassembled and a suitable reply is generated, this reply is shown in the tx buffer. If the message fails the CRC then the decoding buffer is discarded and the rx buffer is left unchanged.

The rx buffer is setup in a loop so that each incoming byte is written progressively along the buffer until all 255 bytes have been used, at this point the program loops back starting on the first rx buffer location once mode.

However as decoded messages are removed from the buffer the buffer normally appears empty as above.

Links:

 

VB2017 MODBUS RTU SLAVE (Program Only)

VB2017 MODBUS RTU SLAVE (Project)